//package pro30015_sinoss;
//
//import java.io.FileNotFoundException;
//import java.io.FileOutputStream;
//import java.io.OutputStreamWriter;
//import java.sql.Connection;
//import java.sql.SQLException;
//import java.util.List;
//
//import org.firefly.db.dialect.IDialect;
//import org.firefly.db.dialect.MySQLDialect;
//import org.firefly.db.dialect.OracleDialect;
//import org.firefly.db.meta.FK;
//import org.firefly.db.meta.IConstraint;
//import org.firefly.db.meta.PK;
//import org.firefly.db.meta.TableMeta;
//import org.firefly.db.util.DBUtils;
//
//public class Main {
//	static Connection tarConn = null;
//	static IDialect tarDia = null;
//	static FileOutputStream fos = null;
//	static{
//		try {
//			Class.forName("oracle.jdbc.driver.OracleDriver");
//			tarConn = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@172.16.236.128:1521:orcl","pro30015", "eplugger");
//			tarDia =  new OracleDialect(tarConn,"PRO30015");
//			fos = new FileOutputStream("/Users/firefly/Desktop/update2.sql");
//		} catch (SQLException e) {
//			e.printStackTrace();
//		} catch (ClassNotFoundException e) {
//			e.printStackTrace();
//		} catch (FileNotFoundException e) {
//			e.printStackTrace();
//		}
//	}
//	
//	/**
//	 * 生成主外键
//	 * @param args
//	 * @throws Exception
//	 */
//	public static void main2(String[] args) throws Exception {
//		List<TableMeta> tMls = tarDia.getTableMetas(false,true,true,null);
//		OutputStreamWriter osw = new OutputStreamWriter(fos);
//		for (TableMeta tm : tMls) { 
//			//3.构建约束信息
//			for (IConstraint c : tm.getConstraintLs()) {
//				if(PK.class.isInstance(c)){
//					// 3.1 构建主键约束
//					String pkSql = DBUtils.buildAddPKSQL((PK)c, tarDia);
//					if(pkSql!=null)
//					osw.write(pkSql+";\n");
//				}else if(FK.class.isInstance(c)){
//					// 3.2 构建外键约束
//					String fkSql = DBUtils.buildAddFKSQL((FK)c, tarDia);
//					if(fkSql!=null)
//					osw.write(fkSql+";\n");
//				}
//			}
//		}
//		osw.flush();
//		osw.close();
//	}
//	
//	/**
//	 * 生成配置表数据
//	 * @param args
//	 * @throws Exception
//	 */
//	public static void main(String[] args) throws Exception {
//		Class.forName("com.mysql.jdbc.Driver");
//		Connection srcConn = java.sql.DriverManager.getConnection(
//				"jdbc:mysql://127.0.0.1:3306/youwoapp?useUnicode=true&characterEncoding=utf-8&autoReconnect=true",
//				"youwo", "123456");
//		IDialect srcDia = new MySQLDialect(srcConn,null);
//		OutputStreamWriter osw = new OutputStreamWriter(fos);
//		//1\导出entity_meta
//		DBUtils.expertInsertSQL(srcConn, srcDia,tarDia,osw, new String[] { "sys_entity_meta" }, " where beanid in('categoryEntry','categoryTab','checkData','group','menu','meta','subSystem','sysParam','user')",false);
//		//2.0\导出场景biz_cfg_edit_table
//		DBUtils.expertInsertSQL(srcConn, srcDia,tarDia,osw, new String[] { "biz_cfg_edit_table" }, " where sceneid in (select id from BIZ_CFG_SCENE where beanid in('categoryEntry','categoryTab','checkData','group','menu','meta','subSystem','sysParam','user'))",false);
//		//2.1\导出场景biz_cfg_export
//		DBUtils.expertInsertSQL(srcConn, srcDia,tarDia,osw, new String[] { "biz_cfg_export" }, " where sceneid in (select id from BIZ_CFG_SCENE where beanid in('categoryEntry','categoryTab','checkData','group','menu','meta','subSystem','sysParam','user'))",false);
//		//2.2\导出场景biz_cfg_form
//		DBUtils.expertInsertSQL(srcConn, srcDia,tarDia,osw, new String[] { "biz_cfg_form" }, " where sceneid in (select id from BIZ_CFG_SCENE where beanid in('categoryEntry','categoryTab','checkData','group','menu','meta','subSystem','sysParam','user'))",false);
//		//2.3\导出场景biz_cfg_scene
//		DBUtils.expertInsertSQL(srcConn, srcDia,tarDia,osw, new String[] { "biz_cfg_scene" }, " where beanid in('categoryEntry','categoryTab','checkData','group','menu','meta','subSystem','sysParam','user')",false);
//		//2.4\导出场景biz_cfg_stat
//		DBUtils.expertInsertSQL(srcConn, srcDia,tarDia,osw, new String[] { "biz_cfg_stat" }, " where sceneid in (select id from BIZ_CFG_SCENE where beanid in('categoryEntry','categoryTab','checkData','group','menu','meta','subSystem','sysParam','user'))",false);
//		//2.5\导出场景biz_cfg_table
//		DBUtils.expertInsertSQL(srcConn, srcDia,tarDia,osw, new String[] { "biz_cfg_table" }, " where sceneid in (select id from BIZ_CFG_SCENE where beanid in('categoryEntry','categoryTab','checkData','group','menu','meta','subSystem','sysParam','user'))",true);
//		//3.0\导出场景cfg_category_entry
//		//DBUtils.expertInsertSQL(srcConn, srcDia,tarDia,osw, new String[] { "CFG_CATEGORY_ENTRY" }, " where sceneid in (select id from BIZ_CFG_SCENE where beanid in('categoryEntry','categoryTab','checkData','group','menu','meta','subSystem','sysParam','user'))",false);
//		//3.1\导出场景cfg_category
//		//DBUtils.expertInsertSQL(srcConn, srcDia,tarDia,osw, new String[] { "CFG_CATEGORY" }, " where sceneid in (select id from BIZ_CFG_SCENE where beanid in('categoryEntry','categoryTab','checkData','group','menu','meta','subSystem','sysParam','user'))",true);
//	}
//	
//}
